package local.michel.util;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.Buffer;

import javax.imageio.ImageIO;

import com.google.common.base.Objects.ToStringHelper;

public class PicAction {

	private File sourceFile;
	private File destFile;
	private boolean resultAvailable;
	private boolean isSame;
	private BufferedImage img1;
	private BufferedImage img2;

	public PicAction(File source, File destination) {
		this.sourceFile = source;
		this.destFile = destination;

		resultAvailable = false;
		img1 = null;
		img2 = null;
	}

	public boolean resultAvailable() {
		return resultAvailable;
	}

	public boolean isSame() {
		return isSame;
	}

	public void setSame() {
		isSame = true;
		deleteImages();
	}

	public void setDifferent() {
		isSame = false;
		deleteImages();
	}

	public File getDest() {
		return destFile;
	}

	public File getSource() {
		return sourceFile;
	}

	public String toString() {
		return "PicAction: src: " + sourceFile.getAbsoluteFile() + ", dest: " + 
				destFile.getAbsoluteFile() + ", same: " + (isSame ? "true" : "false");
	}

	public boolean hasImages() {
		if ((img1 != null) && (img2 != null)) 
			return true;
		return false;
	}

	public void loadImages() {
		try {
			img1 = ImageIO.read(sourceFile);
			img2 = ImageIO.read(destFile);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	protected void deleteImages() {
		img1 = null;
		img2 = null;
	}

	public BufferedImage getSourceImage() {
		return img1;
	}
	
	public BufferedImage getDestImage() {
		return img2;
	}
}
